<?php

namespace App\Http\Controllers\Divide;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\Divide\PdLevel;
use App\Models\Divide\SplitSystem;
use Illuminate\Http\Request;

class DivideSystemController extends Controller
{
    use ResponseData;
    //
    public function list(SplitSystem $model, Request $request){
        $data = $model->query()->get();
        return $this->success($data);
    }
    public function save(SplitSystem $model, Request $request){
        $data = $request->all();
        if(!$request->filled('system_id')) {
            $res = $model->query()->create($data);
            if($res){
                $this->createSystem($res);
                $this->RegionalAgent($res);
                $this->AgentSystem($res);
                $this->ShareLink($res);
            }
        }else{
            $divide = $model->query()->where('system_id',$request->system_id)
                ->first();
            if($divide){
                $divide->update($data);
            }
        }
        return $this->success('更新成功');
    }

}
